package com.example.springbootdemo09.service.impl;

import com.example.springbootdemo09.domain.Teacher;
import com.example.springbootdemo09.mapper.TeacherMapper;
import com.example.springbootdemo09.query.TeacherQuery;
import com.example.springbootdemo09.service.ITeacherService;
import com.example.springbootdemo09.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class TeacherServiceImpl implements ITeacherService {
    @Autowired
    private TeacherMapper igm;

    @Override
    public R add(Teacher teacher) {
        igm.add(teacher);
        return R.ok();
    }

    @Override
    public List<Teacher> findAll() {
        return igm.findAll();
    }

    @Override
    public Teacher findOne(Long id) {
        return igm.findOne(id);
    }
    @Transactional
    @Override
    public R updete(Teacher teacher) {
        igm.updete(teacher);
        return R.ok();
    }
    @Transactional
    @Override
    public R delete(Long id) {
        igm.delete(id);
        return R.ok();
    }

    @Override
    public R fenye(TeacherQuery teacherQuery) {
        Map<String, Object> map = new HashMap<>();
        Integer cont = igm.getCont(teacherQuery);
        List<Teacher> data = igm.getData(teacherQuery);
        map.put("cont", cont);
        map.put("data", data);
        return R.ok(map);
    }
    @Transactional
    @Override
    public R pathDele(Long[] id) {
        igm.pathDele(id);
        return R.ok();
    }
}
